package 华为;

import java.util.*;

public class HuaWei1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        List<String> ans = new ArrayList<>();
        Map<String, Node> map = new HashMap<>();
        Set<Node> set = new HashSet<>();
        Set<Node> right = new HashSet<>();

        for (int i = 0; i < n; i++) {
            String s = scanner.nextLine();
            String[] ss = s.split(" ");
            Node pre,next;
            if(!map.containsKey(ss[0])){
                pre = new Node(ss[0]);
                map.put(ss[0],pre);
                set.add(pre);
            }else{
                pre = map.get(ss[0]);
            }
            if(!map.containsKey(ss[1])){
                next = new Node(ss[1]);
                map.put(ss[1],next);
                right.add(next);
            }else{
                next = map.get(ss[1]);
            }
            pre.next = next;
        }
        set.removeIf(right::contains); // 函数式变成，过滤器函数， 传参1 return boolean
        String compare = scanner.nextLine();
        set.forEach(s->{
            StringBuilder sb = new StringBuilder("");
            boolean flag = false; // 表示这一次遍历到最后是不是我们所要的根据域名
            while (s!=null){
                if(!s.value.equals(compare)){
                    sb.append(s.value);
                    sb.append(".");
                }else{
                    sb.append(compare);
                    flag = true;
                    break;
                }
                s = s.next;
            }
            if(flag){
                ans.add(sb.toString());
            }
        });
        ans.sort(String::compareTo);
        ans.forEach(System.out::println);
    }
}

class Node{
    public String value;
    public Node next;
    public Node(String value){
        this.value = value;
    }
}